# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymongo


class TencentPipeline(object):

    def open_spider(self, spider):
        #MongoDB客户端连接对象.数据库名.集合名
        self.conn = pymongo.MongoClient().tencent.list

    def process_item(self, item, spider):
        self.conn.insert(dict(item))

        return item

    def close_spider(self, spider):
        #关闭数据库连接  NoSQL好像不用关闭
        #self.conn.close()
        pass
